package com.hanxiaozhang.system.dao;

import com.hanxiaozhang.system.entity.UserRoleEntity;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * 用户角色关联表
 *
 * @author hanxiaozhang
 * @email hanxiaozhang2018@sina.com
 * @date 2021-04-01
 */
@Mapper
public interface UserRoleDao {

	UserRoleEntity get(Long userRoleId);
	
	List<UserRoleEntity> list(Map<String, Object> map);

	int save(UserRoleEntity userRole);
	
	int update(UserRoleEntity userRole);


	int batchSave(List<UserRoleEntity> roleMenus);

	/**
	 * 通过角色id查询
	 *
	 * @param roleId
	 * @return
	 */
	@Select("SELECT * FROM sys_user_role WHERE role_id = #{roleId} AND  del_flag=0")
	List<UserRoleEntity> listByRoleId(@Param("roleId") Long roleId);

	/**
	 * 通过用户id查询
	 *
	 * @param userId
	 * @return
	 */
	@Select("SELECT * FROM sys_user_role WHERE user_id = #{userId} AND  del_flag=0")
	List<UserRoleEntity> listByUserId(@Param("userId") Long userId);

	/**
	 * 通过角色id集合查询
	 *
	 * @param roleIds
	 * @return
	 */
	List<UserRoleEntity> listByRoleIds(@Param("roleIds") List<Long> roleIds);

	/**
	 * 通过用户id集合查询
	 *
	 * @param userIds
	 * @return
	 */
	List<UserRoleEntity> listByUserIds(@Param("userIds") List<Long> userIds);


	/**
	 * 通过用户id删除
	 *
	 * @param userId
	 * @return
	 */
	@Update("UPDATE sys_user_role SET del_flag = 1  WHERE user_id = #{userId} AND  del_flag = 0")
	int removeByUserId(@Param("userId") Long userId);

	/**
	 * 通过用户id集合批量删除
	 *
	 * @param userIds
	 * @return
	 */
	int batchRemoveByUserIds(Long[] userIds);

}
